// pages/jiankang/jiankang.js

import WxParse from '../../wxParse/wxParse.js';
import util from '../../utils/util.js';
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: [
      '../images/banner.jpg',
      '../images/banner.jpg',
      '../images/banner.jpg'
    ],
    hostUrl: app.globalData.hostUrl,
    vertical: 'false',
    autoplay: 'true',
    interval: '3000',
    duration: '800',
    dots: 'true',
    autoplay: 'true',
    interval: '5000',
    duration: '300',
    sxvertical: 'true',
    ice: [{
        img: '../images/tu.png',
        text: '当季热卖1',
        text2: '最低2折起>',
        text3: '当季热卖3',
        text4: '最低2折起>'
      },
      {
        img: '../images/tu.png',
        text: '当季热卖2',
        text2: '最低2折起>',
        text3: '当季热卖5',
        text4: '最低2折起>'
      },
      {
        img: '../images/tu.png',
        text: '当季热卖7',
        text2: '最低2折起>',
        text3: '当季热卖6',
        text4: '最低2折起>'
      }

    ],

    xin: [{
        tupian: '../images/img.png',
        tee: '名称123',
        tee2: '介绍介绍介绍',
        tee3: '￥464.00',
        tee4: '立即购买'
      },
      {
        tupian: '../images/img.png',
        tee: '名称7895',
        tee2: '介绍介绍介绍',
        tee3: '￥7454.00',
        tee4: '立即购买'
      },
      {
        tupian: '../images/img.png',
        tee: '介绍123',
        tee2: '介绍介绍介绍',
        tee3: '￥5734.00',
        tee4: '立即购买'
      }
    ],
    listData: [
    {
      id: 1,
      memberNickname: '列表1',
      remainTime: 86400000
    },
    {
      id: 2,
      memberNickname: '列表2',
      remainTime: 3226000
    },
    {
      id: 3,
      memberNickname: '列表3',
      remainTime: 15000
    }
    ],
    // 上下轮播
    titleClick: '13',
    sxtime2: '五月',
    sxSwiper: [{
        sxText1: '春季上新，女神季满撒飒飒减优惠，全场3折起\n',
        sxText2: '春季上新，女神季满减优惠，全场3折起\n',
      },
      {
        sxText1: '春季上新，女神季满减飒飒优惠，全场3折起\n',
        sxText2: '春季上新，女神季满减优惠，全场3折起\n',
      }
    ],
    // 选项卡
    currentIndex: 0,
    firstList: [{
        qgimg: '../images/tu.png',
        rmb: '99',
        jstime: '05:10',
      },
      {
        qgimg: '../images/tu.png',
        rmb: '99',
        jstime: '05:10',
      },
    ],
    "secondList": ["GFF", "GFF", "GFF", "GFF", "GFF", "GFF", "GFF", "GFF"],


    qnumFor: [{
        qnum: '0'
      },
      {
        qnum: '0'
      },
      {
        qnum: '0'
      },
      {
        qnum: '0'
      },
    ],
    num: 4,
    name:''

  },
  //失去焦点
  search_up:function(e){
    var name = e.detail.value;
    this.setData({
      name:name
    })
  },
  //搜索
  search: function (e) {
    wx.navigateTo({
      url: '../new_inter/shop_list/shop_list?name='+this.data.name+"&c1=",
    })
  },
  tabClick(val) {
    this.activeIndex = val;
    this.$apply();
  },
  //swiper切换时会调用
  pagechange: function(e) {
    if ("touch" === e.detail.source) {
      let currentPageIndex = this.data.currentIndex
      // currentPageIndex = (currentPageIndex + 1) %2
      this.setData({
        currentIndex: currentPageIndex
      })
    }
  },

  //用户点击tab时调用
  titleClick: function(e) {
    console.log(e)
    // let currentPageIndex =
      this.setData({
        //拿到当前索引并动态改变
        currentIndex: e.currentTarget.dataset.idx
      })
  },
  xiangqing:function(e){
    wx.navigateTo({
      url: '../details/details?id=' + e.currentTarget.dataset.id,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.jiankang_shop();
    //获取月份  
    var timestamp = Date.parse(new Date());
    var date = new Date(timestamp);
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);

    //获取当日日期 
    var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
    this.setData({
      month: M,
      day: D,
      foot: wx.getStorageSync('foot'),
      is_show: wx.getStorageSync('is_show')
      
    })
  },
  /**
    * 倒计时
    */
  setCountDown: function () {
    let time = 1000;
    let miaosha=this.data.miaosha;
    for (let i = 0; i < miaosha.length; i++) {
      for (let s = 0; s < miaosha[i]['product'].length;s++){
        if (miaosha[i]['product'][s]['remainTime']<=0){
          continue;
        }
        // console.log(miaosha[i]['product'][s]['remainTime'],'到期时间')
        let dao_time = this.getFormat(miaosha[i]['product'][s]['remainTime']);
        miaosha[i]['product'][s]['dao_time'] = dao_time;
        miaosha[i]['product'][s]['remainTime'] -= time;
        this.setData({
          miaosha: miaosha
        })
        // console.log(this.data.miaosha,'更新后数组')
      }
    }
    setTimeout(this.setCountDown, time);
  },

  /**
   * 格式化时间
   */
  getFormat: function (msec) {
    let ss = parseInt(msec / 1000);
    let ms = parseInt(msec % 1000);
    let mm = 0;
    let hh = 0;
    let day = 0;

    if (ss > 60) {
      mm = parseInt(ss / 60);
      ss = parseInt(ss % 60);
      if (mm > 60) {
        hh = parseInt(mm / 60);
        mm = parseInt(mm % 60);
        day = parseInt(hh / 24);
        
      }
    }
    ss = ss > 9 ? ss : `0${ss}`;
    mm = mm > 9 ? mm : `0${mm}`;
    hh = hh > 9 ? hh : `0${hh}`;
    hh -= day*21;

    return day+'天'+hh+'小时:' + mm+'分:' + ss ;
  },
  jiankang_shop: function() {
    var that = this;
    wx.request({
      url: app.globalData.apiUrl + 'Index/jiankang_shop',
      data: {
        // opt: 'getBanner',
        userId:wx.getStorageSync('userId') ,
      },
      header: {
        'content-type': 'application/json'
      },
      success: function(res) {
        // console.log(res)
        if (res.data != null) {
          that.setData({
            info: res.data,
            miaosha:res.data.time,
            time: res.data.header_time,
            group: res.data.group,
            discount: res.data.discount,

          })

        }
       that.setCountDown();
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  index: function() {
    wx.reLaunch({
      url: '../index/index'
    })
  },
  // dichan: function() {
  //   wx.navigateTo({
  //     url: '../dichan/dichan'
  //   });
  // },
  // news: function() {
  //   wx.navigateTo({
  //     url: '../news/news'
  //   });
  // },
})